package UI;

import Model.student;
import Service.Crudservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet("/one")
public class selectonestudentControl extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        Crudservice crudservice = new Crudservice();
        String id = req.getParameter("id");
        Integer id1 = Integer.valueOf(id);
        try {
            student student = crudservice.selectOneService(id1);
            Integer id2 = student.getId();
            String name = student.getName();
            Integer age = student.getAge();
            String height = student.getHeight();
            String school = student.getSchool();
            req.setAttribute("id", id2);
            req.setAttribute("name",name);
            req.setAttribute("age", age);
            req.setAttribute("height", height);
            req.setAttribute("school", school);
            req.getRequestDispatcher("selectone.jsp").forward(req, resp);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        this.doGet(req, resp);
    }
}
